{% extends "xhs/layout.html" %}

{% block title %}小红书数据管理系统 - {% if action == 'add' %}添加笔记{% else %}编辑笔记{% endif %}{% endblock %}

{% block page_title %}{% if action == 'add' %}添加笔记{% else %}编辑笔记{% endif %}{% endblock %}

{% block content %}
<div class="card">
    <div class="card-body">
        <form method="post" action="{% if action == 'add' %}{{ url_for('xhs.add_note') }}{% else %}{{ url_for('xhs.edit_note', note_id=note.id) }}{% endif %}">
            <div class="form-group">
                <label for="title">标题 <span class="text-danger">*</span></label>
                <input type="text" class="form-control" id="title" name="title" value="{{ note.title if note else '' }}" required>
            </div>
            
            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label for="author">作者</label>
                        <input type="text" class="form-control" id="author" name="author" value="{{ note.author if note else '' }}">
                    </div>
                </div>
                
                <div class="col-md-6">
                    <div class="form-group">
                        <label for="keyword">关键词</label>
                        <select class="form-control" id="keyword" name="keyword">
                            <option value="">-- 选择关键词 --</option>
                            {% for kw in keywords %}
                            <option value="{{ kw }}" {% if note and note.keyword == kw %}selected{% endif %}>{{ kw }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
            </div>
            
            <div class="form-group">
                <label for="content">内容</label>
                <textarea class="form-control" id="content" name="content" rows="8">{{ note.content if note else '' }}</textarea>
            </div>
            
            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label for="edit_time">编辑时间</label>
                        <input type="text" class="form-control" id="edit_time" name="edit_time" value="{{ note.edit_time if note else '' }}" placeholder="例如: 05-04 北京">
                        <small class="form-text text-muted">格式: 月-日 地点，例如: 05-04 北京</small>
                    </div>
                </div>
                
                {% if action == 'add' %}
                <div class="col-md-6">
                    <div class="form-group">
                        <label for="url">笔记URL</label>
                        <input type="text" class="form-control" id="url" name="url" value="{{ note.url if note else '' }}" placeholder="https://www.xiaohongshu.com/note/...">
                    </div>
                </div>
                {% endif %}
            </div>
            
            <div class="row">
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="likes">点赞数</label>
                        <input type="number" class="form-control" id="likes" name="likes" value="{{ note.likes if note and note.likes else 0 }}" min="0">
                    </div>
                </div>
                
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="collects">收藏数</label>
                        <input type="number" class="form-control" id="collects" name="collects" value="{{ note.collects if note and note.collects else 0 }}" min="0">
                    </div>
                </div>
                
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="comments">评论数</label>
                        <input type="number" class="form-control" id="comments" name="comments" value="{{ note.comments if note and note.comments else 0 }}" min="0">
                    </div>
                </div>
            </div>
            
            <div class="text-center mt-4">
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-save"></i> 保存
                </button>
                <a href="{% if note %}{{ url_for('xhs.note_detail', note_id=note.id) }}{% else %}{{ url_for('xhs.notes_list') }}{% endif %}" class="btn btn-secondary ml-2">
                    <i class="fas fa-times"></i> 取消
                </a>
            </div>
        </form>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
    $(document).ready(function() {
        // 添加新关键词
        $('#keyword').on('change', function() {
            if ($(this).val() === 'new') {
                var newKeyword = prompt('请输入新关键词:');
                if (newKeyword) {
                    // 添加新选项
                    $(this).append(new Option(newKeyword, newKeyword, true, true));
                } else {
                    // 如果取消，重置为空
                    $(this).val('');
                }
            }
        });
    });
</script>
{% endblock %} 